// 审核计划表
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="年份">
        <el-date-picker type="year" v-model="queryParams.year" format="yyyy" value-format="yyyy"
          :style="{ width: '100%' }" placeholder="请选择年份" clearable></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['manageAudit:summary:add']">新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manageAudit:summary:export']"
          >导出</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="printBox"
          v-hasPermi="['manageAudit:summary:print']">打印</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table @selection-change="handleSelectionChange" fit v-loading="loading" border :data="dataList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column show-overflow-tooltip label="录入日期"  prop="recordTime" />
      <el-table-column show-overflow-tooltip label="填写人" prop="userName" />
      <el-table-column show-overflow-tooltip label="填写内容" min-width="320" prop="content">
        <template slot-scope="scope">
          <div v-html="scope.row.content" style="height: 75px;"></div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="240" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['manageAudit:summary:info']"
            @click="handleDetail(scope.row)">详情</el-button>

          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['manageAudit:summary:edit']">修改</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <el-dialog :visible.sync="openFile" :title="type == 1 ? '首次签到表' : type == 2 ? '末次签到表' : '总结报告'" width="800"
      append-to-body>
      <el-form :disabled="isEdit" ref="elForm" :model="formData" :rules="rules" size="medium" label-width="120px">
        <el-form-item label="" prop="filePath">
          <fileUpload :isDelete="!isEdit" v-model="formData.filePath"></fileUpload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!isEdit">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="openFile = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 打印模板位置 -->
    <PrintBox :checkNum="9" :printRow="printList" :isPageSize="false" id="printBox">

      <template slot-scope="scope">
        <div>
          <div style="margin:0; white-space: pre-wrap;text-align: justify" v-html="scope.item.content"></div>
          <div style="height: 200px;margin-top: 50px;text-align: end;">
            <template>
              <img style="width: 80px; " :src="baseUrl + scope.item.esign" />
            </template>
            <!-- <div style="width: 100%;display: inline-block;margin-top: 20px;">{{ new
              Date(scope.item.recordTime.substring(0, 10)).getFullYear() }}年{{ String(new
    Date(scope.item.recordTime.substring(0, 10)).getMonth() + 1).padStart(2, '0') }}月{{ String(new
    Date(scope.item.recordTime.substring(0, 10)).getDate() + 1).padStart(2, '0') }}日</div> -->
            <div>{{ scope.item.recordTime }}</div>
          </div>
        </div>
      </template>
    </PrintBox>
  </div>
</template>

<script>
import printStyle from "@/utils/print.js";

import {
  listmanagerAudit,
  delmanagerAudit,
  effectauditPlan,
  signFile
} from "@/api/quality/manageAudit/plan.js";
import { listsummaryMaterial } from "@/api/quality/materials.js"
export default {
  name: "listmanagerAudit",
  data() {
    return {
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: 1,
        ipAddress: this.$VUE_APP_IMG_API
        // auditYear: undefined,
      },
      // 日期范围
      dateRange: [],
      baseUrl: this.$VUE_APP_IMG_API,
      openFile: false,
      type: 1,
      current: {},
      formData: { filePath: undefined },
      infos: [], //勾选的数据
      printList: [],

    };
  },
  created() {
    this.getList();
    console.log(this.$store.state.user.id);
  },
  methods: {
    printBox() {
      //infos  勾选的数据 如果有勾选就打印勾选。
      if (this.infos.length) {
        this.printList = this.infos;
      } else {
        //反之打印当前整个列表
        this.printList = this.dataList;
      }
      setTimeout(() => {
        document.title = "年度管理评审工作计划 STET/B/13-1";

        this.$print({
          printable: "printBox", //打印区域id
          type: "html", //打印类型是html
          scanStyles: false,
          targetStyles: ["*"],
          style: this.workStyle(),
          onPrintDialogClose: () => {
            document.title = process.env.VUE_APP_TITLE;
          },
        });
      }, 500);
    },
    // 可以自定义样式  printStyle 是公共样式 切勿私自修改
    workStyle() {
      return `${printStyle}
        table,
        table tr th,
        table tr td {
          height:20mm;
          padding: 4px;
        }
        .desc{
        text-align: left; font-size: 12px; margin-top: 10px
      }
            .df {
                display: flex;
              }
      `;
    },
    handleFile(row, type, isEdit = false) {
      try {
        this.formData = { filePath: undefined };
        this.type = type;
        this.current = row;
        this.isEdit = false;
        if (this.type == 1 && this.current.firstSignFile) {
          this.formData.filePath = this.current.firstSignFile;
          this.isEdit = true;
        }
        if (this.type == 2 && this.current.endSignFile) {
          this.formData.filePath = this.current.endSignFile;
          this.isEdit = true;
        }
        if (this.type == 3 && this.current.report) {
          this.formData.filePath = this.current.report;
          this.isEdit = true;
        }
        if (isEdit) this.isEdit = false
      } catch (error) {
        console.log(error);
      }
      this.openFile = true;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.innerManagerAuditId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.infos = selection;

    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      const configId = row.summaryMaterialId || this.ids;
      this.$router.push("./summaryAdd?isEdit=true&id=" + configId);
    },
    /** 提交按钮 */
    submitForm() {

      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          this.formData.type = this.type;
          this.formData.summaryMaterialId = this.current.summaryMaterialId;
          signFile(this.formData).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.openFile = false;
            this.getList();
          });
        }
      });
    },
    handleDetail(row) {
      console.log(row);
      this.$router.push(
        "./summaryAdd?isInfo=true&id=" + row.summaryMaterialId
      );
      //   this.$router.push({
      //     path: "/manageAudit/process/detail/" + row.piid,
      //     query: {
      //       definitionId: null,
      //       deployId: null,
      //       taskId: null,
      //       finished: false,
      //       id: row.innerManagerAuditId,
      //     },
      //   });
      // this.$router.push("./addBuy?isInfo=true&id=" + row.deviceBuyId);
    },
    // 更多操作触发
    handleCommand(command, row) {

      switch (command) {
        case "handleDelete":
          this.handleDelete(row);
          break;
        case "handleFileFirst":
          this.handleFile(row, 1);
          break;
        case "handleFileLast":
          this.handleFile(row, 2);
          break;
        case "handleSummary":
          this.handleFile(row, 3);
          break;
        case "handleCorrent":
          this.handleCorrent(row);
          break;
        case "addLogConent":
          this.addLogConent(row);
          break;
      }
    },
    addLogConent(row) {
      this.$router.push("./addInAudit?planId=" + row.innerManagerAuditId);
    },
    handleStatusChange(row) {
      let text = row.effectStatus == "1" ? "启用" : "禁用";
      this.$modal
        .confirm(
          '确认要"' + text + '""' + row.innerManagerAuditId + '"数据吗？'
        )
        .then(function () {
          return effectauditPlan(row.innerManagerAuditId, row.effectStatus);
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.effectStatus = row.effectStatus == "0" ? "1" : "0";
        });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.innerManagerAuditId || this.ids;
      let name = this.checkRow(
        configId,
        this.dataList,
        "innerManagerAuditId",
        "DELETE",
        "year"
      );
      this.$modal
        .confirm('是否确认删除id为"' + configId + '"的数据项？')
        .then(function () {
          return delmanagerAudit(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    handleAdd() {
      this.$router.push("./summaryAdd");
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listsummaryMaterial(
        // this.addDateRangeTime(
        this.queryParams,
        //   this.dateRange,
        //   "startAuditDate",
        //   "endAuditDate"
        // )
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleExport() {
      this.download(

        "system/managerAudit/export",
        {
          ...this.queryParams,
        },
        `管理审核计划记录表_${this.parseTime(
          new Date().getTime(),
          "{y}-{m}-{d}"
        )}.xlsx`
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
